package apps.AfterDlcs.afterDlcsBL.buff;

import apps.AfterDlcs.AfterDlcs;
import apps.AfterDlcs.afterDlcsBL.Event;
import apps.AfterDlcs.afterDlcsBL.Keys;
import apps.AfterDlcs.afterDlcsBL.buff.myBuff.Attack.NormalAttackBuff;
import apps.AfterDlcs.afterDlcsBL.buff.myBuff.Base.BaseAttackBuff;
import apps.AfterDlcs.afterDlcsBL.buff.myBuff.Base.BaseBuffBuff;
import apps.AfterDlcs.afterDlcsBL.buff.myBuff.Base.BaseDoTestBuff;
import apps.AfterDlcs.afterDlcsBL.buff.myBuff.Base.BaseGetValueBuff;
import apps.AfterDlcs.afterDlcsBL.hero.Hero;
import backs.dataBase.DBNormal;

import java.util.ArrayList;
import java.util.List;

public class Buff
{
    public static int MAX_BUFF_LEVEL=10;
    public String buffName;
    public int worldID,buffID,level;
    public Long lastTime;
    public Hero owner,giver;
    public String type;
    public static Buff initBuffByBuffID(Hero owner,int worldID, int buffID,int level)
    {
        String buffClass=BuffBL.getBuffValue(worldID,buffID,"class");
        try
        {
            Class<?> clazz = Class.forName("apps.AfterDlcs.afterDlcsBL.buff.myBuff." + buffClass);
            Buff buff = (Buff) clazz.newInstance();
            buff.init(owner,worldID,buffID,level);
            return buff;
        }
        catch (Exception e)
        {
            return null;
        }
    }

    public void init(Hero owner,int worldID,int buffID,int level)
    {
        this.worldID=worldID;
        this.owner=owner;
        this.buffID=buffID;
        this.level=level;
        this.giver=Hero.getHero(worldID,Integer.parseInt(BuffBL.getBuffValue(worldID,buffID,"giverID")));
        this.lastTime=Long.parseLong(BuffBL.getBuffValue(worldID,buffID, Keys.LAST_TIME,"-1",false));
        this.type=BuffBL.getBuffValue(worldID,buffID,"type","base",false);
        initValue();
    }

    public Buff setBuff(Hero owner,Hero giver,int worldID,int buffID,int level,String type,Long lastTime)
    {
        this.worldID=worldID;
        this.owner=owner;
        this.buffID=buffID;
        this.level=level;
        this.type=type;
        this.lastTime=lastTime;
        this.giver=giver;
        return this;
    }

    public void initValue()
    {

    }

    public static List<Buff> getBaseBuffList(Hero owner,int group)
    {
        List<Buff> buffList=new ArrayList<>();
        buffList.add(new BaseGetValueBuff().setBuff(owner,owner,group,0,0,"base",-1L));
        buffList.add(new BaseBuffBuff().setBuff(owner,owner,group,0,0,"base",-1L));
        buffList.add(new BaseDoTestBuff().setBuff(owner,owner,group,0,0,"base",-1L));
        buffList.add(new BaseAttackBuff().setBuff(owner,owner,group,0,0,"base",-1L));
        return buffList;
    }

    public void saveBuff()
    {
        if(level==0) return;
        DBNormal.insertIfNotListValue(AfterDlcs.dbName,worldID,owner.heroID+"_buffList_level_"+level,buffID+"");
        BuffBL.setBuffValue(worldID,buffID,"type",type);
        BuffBL.setBuffValue(worldID,buffID,Keys.LAST_TIME,lastTime+"");
        BuffBL.setBuffValue(worldID,buffID,"giverID",giver.heroID+"");
    }

    public void handleEvent(Event event)
    {

    }


}
